﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;

using System.Data.SqlClient;
using System.Data.Common;

namespace EShop.DAL
{
    public class MSSQL:DbBase
    {
        //internal readonly string MSSQLConnectString = "Server={0};uid={1};pwd={2};Database={3};Connect Timeout={4}";
        private readonly string _connectString;

        /// <summary>
        /// 初始化SQL 连接字符串
        /// </summary>
        /// <param name="connectString">连接字符串</param>
        public MSSQL(string connectString)
        {
            if (string.IsNullOrEmpty(connectString)) throw new ArgumentNullException("SQL 连接字符串不能为空！");

            this._connectString = connectString;
            _provideName = "System.Data.SqlClient";
        }

        //public MSSQL(string server, string uid, string pwd, string database, int timeout)
        //{
        //    this._connectString = string.Format(MSSQLConnectString, server, uid, pwd, database, timeout.ToString());
        //    _provideName = "System.Data.SqlClient";
        //}

        protected override DbConnection CreateConnection()
        {
            _connection = new SqlConnection(_connectString);
            try
            {
                if (_connection != null && _connection.State == ConnectionState.Closed)
                    _connection.Open();
                return _connection;
            }
            catch (Exception e)
            {
                throw e;
            }
        }
    }
}
